package com.zat.mes.andrmes.dofun.work

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.media.RingtoneManager
import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.base.BaseActivity
import com.zat.mes.andrmes.data.PackBean
import com.zat.mes.andrmes.dofun.QrScanActivity
import com.zat.mes.andrmes.dofun.work.vm.GetPackModel
import com.zat.mes.andrmes.dofun.work.vm.WorkRecordViewModel
import com.zat.mes.andrmes.global.CompanionType
import com.zat.mes.andrmes.utils.DisplayUtil
import com.zat.mes.andrmes.utils.ReadCardUtils
import com.zat.mes.andrmes.utils.SystemActivityUtil
import com.zat.mes.andrmes.utils.showToast
import kotlinx.android.synthetic.main.activity_update_dm_qty.*
import kotlinx.android.synthetic.main.dialog_upate_qty.view.*
import kotlinx.android.synthetic.main.layout_title.*
import permissions.dispatcher.*

/**
 * 倒毛数量
 */

class UpdateDmQtyActivity : BaseActivity() {


    private var getPackModel: GetPackModel? = null
    override fun init() {
        initView()
        initData()
    }


    private fun initData() {

        getPackModel = ViewModelProvider(this).get(GetPackModel::class.java)
        getPackModel?.getPackUpdate()?.observe(this, Observer {
            closeLoading()
            showToast(it)

        })

    }


    /**
     * 初始化view
     */
    private fun initView() {
        setContentView(R.layout.activity_update_dm_qty)
        tVtitle.text = "设置倒毛数量"
        rlReturnTitle.visibility = View.VISIBLE
        rlRightComm.visibility = View.VISIBLE
        rlReturnTitle.setOnClickListener { finish() }
        btnUpdateDm.setOnClickListener {

            if (TextUtils.isEmpty(etZhidanDm.text.toString())) {
                showToast("请输入制单号")
                return@setOnClickListener
            }
            if (TextUtils.isEmpty(etGanghaoDm.text.toString())) {
                showToast("请输入缸号")
                return@setOnClickListener
            }
            if (TextUtils.isEmpty(etQtyDm.text.toString())) {
                showToast("请输入数量")
                return@setOnClickListener
            }
            showLoading()
            getPackModel?.postDmQty(
                etZhidanDm.text.toString(),
                etGanghaoDm.text.toString(),
                etQtyDm.text.toString()
            )

        }


    }

}
